<template>
    <div id="app" :style="{ '--themescolor': themes.color }" v-wechat-title="$route.meta.title">
		<HeadBox :titleName="$route.meta.titleName" :customHead="$route.meta.customHead" v-show="$route.meta.showHeadBox" />
        <transition :name="transitionName">
            <keep-alive>
                <router-view v-if="$route.meta.keepAlive" :class="$route.meta.showHeadBox ? 'child-view have-head' : 'child-view'"></router-view>
            </keep-alive>
            <!-- 缓存的页面 -->
        </transition>

        <transition :name="transitionName">
            <router-view v-if="!$route.meta.keepAlive" :class="$route.meta.showHeadBox ? 'child-view have-head' : 'child-view'"></router-view>
            <!-- 不缓存的页面 -->
        </transition>
        <TabBar v-show="$route.meta.showBottomTabBar" />
    </div>
</template>

<script>
import { mapState } from 'vuex'
import { tokenManage } from 'utils/Cache'
import { getUa } from 'utils/utils'
import { oauth2 } from 'api/common/weixin'
import TabBar from 'components/TabBar/TabBar'
import HeadBox from 'components/headBox/headBox'
import router from './router/index'
export default {
    name: 'App',
    components: {
        TabBar,
        HeadBox
    },
    data() {
        return {
            transitionName: 'van-fade',
            tabArr: [],
            page: [],
            displayText: false
        }
    },
    created() {
        this.check = true
    },
    mounted() {
        this.$nextTick(() => {
            this.$store.dispatch('getBaseSetting')
            this.$store.dispatch('loadRule')
			this.$store.dispatch('setDistribution') //设置分销员
            // if (tokenManage.getToken()) {
            //   this.$store.dispatch('getCartGoods')
            // }
        })
    },
    methods: {},
    computed: {
        ...mapState(['bottomColumn', 'themes', 'cartNum'])
    },
    watch: {
        $route(to, from) {
            this.$router.isBack = false
            document.documentElement.scrollTop = 0
            document.body.scrollTop = 0

            if (this.bottomColumn) {
                for (let index = 0; index < this.bottomColumn.pages.length; index++) {
                    const element = this.bottomColumn.pages[index]
                    if (to.meta.type == element.type) {
                        if (element.checked == 1) {
                            to.meta.showBottomTabBar = true
                        } else {
                            to.meta.showBottomTabBar = false
                        }
                    }
                }
            }
        }
    }
}
</script>

<style lang="stylus">
.child-view {
  position: absolute;
  width: 100%;
  left: 0;
  right: 0;
  margin: auto;
}
.have-head {
  padding-top: 44px;
}

//返回按钮的颜色
.van-nav-bar .van-icon {
  color: #4eae31 !important
}
.van-tabs__line {
  height: 2px;
}
</style>
